Failed Conditions
Push — master ( 2a10ca...dc3f81 )
by Yo
01:45
created

wrapper.js ➔ ???   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
c 2
b 0
f 0
nc 8
nop 1
dl 0
loc 11
ccs 1
cts 2
cp 0.5
crap 6
rs 9.2
1
"use strict";
2
3 1
const winston = require('winston');
4 1
const config = require('config');
5 1
const path = require('path');
6 1
const moment = require('moment');
7
8 1
const loggerConfig = config.logger;
9
10 1
const formatFile = options => {
11
    return ' [' + options.level.toUpperCase() + ']'
12
        + '[' + moment(new Date()).format('YYYY-MM-DD HH:mm:ss') + ']'
13
        + (options.message ? ' ' + options.message : '')
14
        + (
15
            options.meta && Object.keys(options.meta).length
16
                ? ' ' + JSON.stringify(options.meta)
17
                : ''
18
        )
19
    ;
20
};
21
22 1
const formatConsole = options => {
23
    return winston.config.colorize(options.level) + ':'
24
        + (options.message ? ' ' + options.message : '')
25
        + (
26
            options.meta && Object.keys(options.meta).length
27
                ? ' ' + winston.config.colorize('data', JSON.stringify(options.meta))
28
                : ''
29
        )
30
    ;
31
};
32
33
/**
34
 * @type {winston.Logger} Default logger wrapper for the whole app. Use console output and a log file
35
 */
36 1
module.exports = new winston.Logger({
37
    transports: [
38
        new winston.transports.Console({
39
            level: config.debug === true ? 'debug' : loggerConfig.level,
40
            name: 'console',
41
            json: false,
42
            colorize: true,
43
            formatter: formatConsole
44
        }),
45
        new winston.transports.File({
46
            name: 'default',
47
            level: config.debug === true ? 'debug' : loggerConfig.level,
48
            filename: path.resolve(loggerConfig.path, './server.log'),
49
            tailable: true,
50
            json: false,
51
            formatter: formatFile
52
        })
53
    ]
54
});
55